$(function(){
	$("#data_table").html('');
	
	backendCommon.closeWin('win_clow');
	$("#del_key").click(function(){
		var host = $.trim($("#host").val());
		var port = $.trim($("#port").val());
		var key = $("#key_1").html();
		if(host == ''){
			alert("请输入host");
			return false;
		}
		if(port == ''){
			alert("请输入port");
			return false;
		}
		if(key == ''){
			alert("请输入key");
			return false;
		}
		var params = {"host": host , "port":port, "key":key};
		$.ajax({
			url:mainDomain + '/info/clearRedis.action',
			dataType: 'json',
			data : params,
			success:function(data){
				if(data!=null && data.success){
					alert("删除成功");
				}else{
					alert("删除失败"+data.message);
				}
				$("#win_clow").window('close');
			}
		});
	});
	
	$("#close_key").click(function(){
		backendCommon.closeWin('win_clow');
	});
});


function submitSearch(){
	$("#data_table").html('');
	var key = $("#param").val();
	if(key == ''){
		alert("请输入缓存key");
		return false;
	}
	var host = $.trim($("#host").val());
	var port = $.trim($("#port").val());
	if(host == ''){
		alert("请输入host");
		return false;
	}
	if(port == ''){
		alert("请输入port");
		return false;
	}
	var params = {"host": host , "port":port, "key":key};
	$.ajax({
		url:mainDomain + '/info/queryRedis.action',
		dataType: 'json',
		data : params,
		success:function(data){
			if(data!=null  && data.success ){
				$("#data_table").html(Process(data.data.resultData));
			}else{
				$("#data_table").html(data.message);
			}
		}
	});
}

function queryRedis(key){
	$("#value_1").val('');
	backendCommon.openeWin('win_clow');
	$("#key_1").html(key);
	$("#win_clow").panel("move",{top:$(document).scrollTop() + ($(window).height()-400) * 0.5 });
	var host = $.trim($("#host").val());
	var port = $.trim($("#port").val());
	if(host == ''){
		alert("请输入host");
		return false;
	}
	if(port == ''){
		alert("请输入port");
		return false;
	}
	var params = {"host": host , "port":port, "key":key};
	$.ajax({
		url:mainDomain + '/info/queryRedis.action',
		dataType: 'json',
		data : params,
		success:function(data){
			if(data!=null  && data.success ){
				$("#value_1").val(data.data.resultData);
			}else{
				$("#value_1").val(data.message);
			}
		}
	});
}

/**
 * 查询所有的key
 * @returns {Boolean}
 */
function submitkeySearch(){
	$("#data_table").html('');
	var key = $("#param").val();
	if(key == ''){
		alert("请输入缓存key");
		return false;
	}
	var host = $.trim($("#host").val());
	var port = $.trim($("#port").val());
	if(host == ''){
		alert("请输入host");
		return false;
	}
	if(port == ''){
		alert("请输入port");
		return false;
	}
	var params = {"host": host , "port":port, "key":key};
	$.ajax({
		url:mainDomain + '/info/getAllKeys.action',
		dataType: 'json',
		data : params,
		success:function(data){
			if(data!=null  && data.success ){
				$("#data_table").html(data.data.resultData);
			}else{
				$("#data_table").html(data.message);
			}
		}
	});
}

function clearForm(){
	$("#data_table").html('');
	var key = $("#param").val();
	if(key == ''){
		alert("请输入缓存key");
		return false;
	}
	delRedis(key);
}

function delRedis(key){
	var host = $.trim($("#host").val());
	var port = $.trim($("#port").val());
	if(host == ''){
		alert("请输入host");
		return false;
	}
	if(port == ''){
		alert("请输入port");
		return false;
	}
	var params = {"host": host , "port":port, "key":key};
	$.ajax({
		url:mainDomain + '/info/clearRedis.action',
		dataType: 'json',
		data : params,
		success:function(data){
			if(data!=null && data.success){
				$("#data_table").html("删除成功");
			}else{
				$("#data_table").html("删除失败"+data.message);
			}
			$("#win_clow").window('close');
		}
	});
}